package com.test2;

import java.util.Scanner;

public class Main4 {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
        //while (in.hasNextInt()) {//注意while处理多个case
            int n = in.nextInt();
            int[] arr = new int[n];
            for(int i=0;i<n;i++){
            	arr[i] = in.nextInt();
            }
            int c=0;
            while(arr.length>0){
            	c++;
            int c1 = 0;
            int c2 = 0;
            for(int i=0;i<arr.length-1;i++){
            	if(arr[i] < arr[i+1]){
            		c1++;
            	}
            	if(arr[i] > arr[i+1]){
            		c2++;
            	}
            }
            
            if(c1 > c2){
            	 for(int i=arr.length-2;i>=0;i--){
                 	if(arr[i] < arr[i+1]){
                 		arr[i+1]=0;
                 	}
                 }
            	 int[] a2 = new int[arr.length-c1];
            	 int j =0;
            	 for(int i=0;i<arr.length;i++){
            		 if(arr[i]!=0)
            		 arr[j++] = arr[i];
            	 }
            	 arr = a2;
            }else{
            	for(int i=arr.length-2;i>=0;i--){
                 	if(arr[i] > arr[i+1]){
                 		arr[i+1]=0;
                 	}
                 }
            	 int[] a2 = new int[arr.length-c1];
            	 int j =0;
            	 for(int i=0;i<arr.length;i++){
            		 if(arr[i]!=0)
            		 arr[j++] = arr[i];
            	 }
            	 arr = a2;
            }
            }
            System.out.println(c);
       // }
	}
	
}
